package com.lm.bouncycastle.example;

import com.lm.bouncycastle.utils.AesUtil;
import com.lm.bouncycastle.utils.HashUtil;
import com.lm.bouncycastle.utils.RsaUtil;

import javax.crypto.SecretKey;
import java.security.KeyPair;

public class CryptoExample {
    public static void main(String[] args) throws Exception {
        SecretKey key = AesUtil.generateKey();
        String cipher = AesUtil.encrypt("hello springboot", key);
        String plain = AesUtil.decrypt(cipher, key);

        System.out.println("加密后: " + cipher);
        System.out.println("解密后: " + plain);

        KeyPair keyPair = RsaUtil.generateKeyPair();
        cipher = RsaUtil.encrypt("secret message", keyPair.getPublic());
        plain = RsaUtil.decrypt(cipher, keyPair.getPrivate());

        System.out.println("RSA 加密后: " + cipher);
        System.out.println("RSA 解密后: " + plain);

        String hash = HashUtil.sha256("springboot+bouncycastle");
        System.out.println("SHA-256: " + hash);
    }
}
